import React,{Component} from 'react';
import '../../style/less/privateLetter.less';
import {message} from 'antd';
import * as fetch from '../../config/fetch';
import {browserHistory} from 'react-router';
import * as pub from '../../config/public';
class PrivateDialogueTheme extends Component {
	constructor(args) {
		super()
		this.state = {
			senderName:'',
			privateletterId:'',
			jumpPage: 1,
			totalPage: 1,
		}	
	}
	componentWillMount(){
		this.setState({
			senderName:localStorage.getItem('username')
		})
	}
	sendLetterTheme(){
		if(this.refs.content.value === ''){
			message.error('发送内容不能为空', 3);
			return
		}
		let formData = new FormData()
		formData.append('senderName',this.state.senderName)
		formData.append('privateletterNote',this.refs.content.value)
		formData.append('addresseeName',this.props.params.id)
		fetch.sendLetterTheme(formData).then((data)=>{
			if(data.result === 'RC100'){
				this.setState({
					privateletterId:data.privateletterId
				},()=>{
					let data = {infoSuccess:true}
					let path = {
						pathname:"/PrivateDialogue/" + this.state.privateletterId,
						state: data
					}
					pub.jumpHistory.push(path)
				})	
			}else{
				message.error(data.errMsg,3)
			}
		})
	}
	render(){
		return(
			<div className="wrapper bg-F0F4F6 privateLetter">
				<div className="layout clearFix pad-t-20">
					
					<div className="row common-title" style={{padding: '10px 30px'}}>私信主题
						<button className="sx-refresh" onClick={()=>{window.history.back()}}>返回</button>
					</div>
					<div className="talk-container">
						<div className="talk-textarea">
							<textarea placeholder="请输入..." required="required" ref='content' value={this.state.textareaValue} onChange={()=>{this.setState({textareaValue:this.refs.content.value})}}></textarea>
							<button type="button" onClick={()=>this.sendLetterTheme()}>确定</button>
						</div>
					</div>
				</div>
			</div>
		)
	}
}






export default PrivateDialogueTheme